CC ?= gcc
CFLAGS=-Wall -O2 -DLINUX -D_GNU_SOURCE
LDFLAGS=-ldl -lpthread
TARGET=capture
OBJECT=capture.o libinput_yuyv.so liboutput_file.so liboutput_viewer.so liboutput_avi.so

CFLAGS_D=-Wall -g -DLINUX -D_GNU_SOURCE
TARGET_D=capture_d
OBJECT_D=capture_d.o libinput_yuyv_d.so liboutput_file_d.so liboutput_viewer_d.so liboutput_avi_d.so
# OBJECT_D=capture_d.o libinput_yuyv_d.so liboutput_viewer_d.so

all:$(TARGET)	

$(TARGET):$(OBJECT)
	$(CC) capture.o $(LDFLAGS) -o capture

libinput_yuyv.so:phony
	make -C input/input_yuyv all CC=$(CC)
	cp input/input_yuyv/libinput_yuyv.so .

liboutput_file.so:phony
	make -C output/output_file all CC=$(CC)
	cp output/output_file/liboutput_file.so .

liboutput_viewer.so:phony
	make -C output/output_viewer all CC=$(CC)
	cp output/output_viewer/liboutput_viewer.so .

liboutput_avi.so:phony
	make -C output/output_avi all CC=$(CC)
	cp output/output_avi/liboutput_avi.so .
	
capture.o:capture.c capture.h
	$(CC) $(CFLAGS) $< -c -o $@

debug:$(TARGET_D)
	
$(TARGET_D):$(OBJECT_D)
	$(CC) capture_d.o $(LDFLAGS)  -o $(TARGET_D)

libinput_yuyv_d.so:phony
	make -C input/input_yuyv debug CC=$(CC)
	cp input/input_yuyv/libinput_yuyv_d.so .

liboutput_file_d.so:phony
	make -C output/output_file debug CC=$(CC)
	cp output/output_file/liboutput_file_d.so .

liboutput_viewer_d.so:phony
	make -C output/output_viewer debug CC=$(CC)
	cp output/output_viewer/liboutput_viewer_d.so .

liboutput_avi_d.so:phony
	make -C output/output_avi debug CC=$(CC)
	cp output/output_avi/liboutput_avi_d.so .
	

capture_d.o:capture.c capture.h
	$(CC) $(CFLAGS_D) $< -c -o $@
clean:
	make -C input/input_yuyv $@
	make -C output/output_file $@
	make -C output/output_viewer $@
	make -C output/output_avi $@
	rm -f *.o *.so *.~ capture a.out capture_d


.PHONY: phony all clean debug
